home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / recent / warpup1.lha / WarpUP-WarpOS / WarpRace / ModSrc / C2P.s < prev   
Text File  |  1997-10-13  |  15KB  |  474 lines

  1.  
  2.                 incdir  include:
  3.                 incdir  lvo:
  4.                 incdir  powerasm:source/powerpc_lib/warprace/
  5.  
  6.                 include powerpc/powerpc.i
  7.                 include warprace.i
  8.  
  9.                 include exec/memory.i
  10.                 include graphics/gfx.i
  11.  
  12.                 include exec_lib.i
  13.                 include graphics_lib.i
  14.  
  15.                 xref    _LinkerDB
  16.                 xref    C2P_PPC
  17.  
  18.                 xdef    bitmap
  19.                 xdef    ChunkyBuffer
  20.  
  21. VERSION         =       1
  22. REVISION        =       0
  23. REVISIONCOUNT   =       1
  24.  
  25. merge           macro
  26.                 move.l  \2,\4
  27.                 move.l  #\5,\3
  28.                 and.l   \3,\2
  29.                 and.l   \1,\3
  30.                 eor.l   \3,\1
  31.                 eor.l   \2,\4
  32.                 ifeq    \6-1
  33.                 add.l   \3,\3
  34.                 else
  35.                 lsl.l   #\6,\3
  36.                 endc
  37.                 lsr.l   #\6,\4
  38.                 or.l    \3,\2
  39.                 or.l    \4,\1
  40.                 endm
  41.  
  42.  
  43.  
  44.  
  45.                 section "",code
  46.  
  47.                 mc68020
  48.  
  49. start
  50.                 movem.l d1-a6,-(sp)
  51.                 lea     _LinkerDB,a4
  52.                 cmp.l   #WR_ID,d0
  53.                 beq.b   .go
  54.                 movem.l (sp)+,d1-a6
  55.                 moveq   #0,d0
  56.                 rts
  57. .go
  58.                 lea     ErrParams,a3
  59.                 move.l  a0,a2
  60.                 move.l  $4.w,_SysBase
  61.                 lea     graf_name,a1
  62.                 move.l  a1,(a3)
  63.                 moveq   #0,d0
  64.                 move.l  d0,4(a3)
  65.                 lea     LibErr,a5
  66.                 CALLEXEC        OpenLibrary
  67.                 move.l  d0,_GfxBase
  68.                 beq.b   .error
  69.                 move.l  #320*256,d0
  70.                 move.l  d0,(a3)
  71.                 move.l  #MEMF_PUBLIC,d1
  72.                 lea     MemErr,a5
  73.                 CALLEXEC        AllocVec
  74.                 move.l  d0,ChunkyBuffer
  75.                 beq.b   .error
  76.                 lea     ChipErr,a5
  77.                 bsr     SetupBitmaps
  78.                 tst.l   d0
  79.                 beq.b   .error
  80.                 move.l  WRI_POWERPCBASE(a2),_PowerPCBase
  81.                 tst     WRI_68K(a2)
  82.                 bne     .notPPC
  83.                 move.l  a2,a0
  84.                 RUNPOWERPC      C2P_PPC
  85.                 bra.w   .done
  86. .notPPC
  87.                 move.l  WRI_STARTTIMER_68K(a2),a1
  88.                 jsr     (a1)
  89.                 moveq   #50-1,d7
  90. .loop
  91.                 move.l  ChunkyBuffer,a0
  92.                 lea     bitmap,a1
  93.                 bsr     ChunkyToPlanar
  94.                 dbra    d7,.loop
  95.                 move.l  WRI_STOPTIMER_68K(a2),a1
  96.                 jsr     (a1)
  97.                 divu.l  #50,d0
  98. .done
  99.                 move.l  d0,Result
  100.                 divul.l #1000,d1:d0
  101.                 move.l  d0,ResultParams
  102.                 move.l  d1,ResultParams+4
  103.                 move.l  #STATUS_SUCCESS,Status
  104.                 bra.b   .end
  105. .error
  106.                 move.l  #STATUS_ERROR,Status
  107.                 move.l  a5,ErrStr
  108. .end
  109.                 move.l  ChunkyBuffer,d0
  110.                 beq.b   .nofree
  111.                 move.l  d0,a1
  112.                 CALLEXEC        FreeVec
  113. .nofree
  114.                 bsr     FreeBitmaps
  115.                 move.l  _GfxBase,d0
  116.                 beq.b   .nograf
  117.                 move.l  d0,a1
  118.                 CALLEXEC        CloseLibrary
  119. .nograf
  120.                 move.l  #WRO,d0
  121.                 movem.l (sp)+,d1-a6
  122.                 rts
  123.  
  124. ******************************************************************************
  125. *
  126. *       d0 = SetupBitmaps
  127. *
  128. *       prepares one bitmap
  129. *
  130. *       Out:
  131. *       d0 = error code
  132. *
  133. *       error codes:    -1 = success
  134. *                        0 = not enough memory
  135. ******************************************************************************
  136. SetupBitmaps
  137.                 movem.l d1/d5-a2,-(sp)
  138.                 lea     bitmap,a0
  139.                 move.l  a0,ActualBitmap
  140. .loop
  141.                 move.l  a0,a2
  142.                 lea     bm_Planes(a2),a2        ;a2 -> planeptrs
  143.                 moveq   #8,d0
  144.                 move.l  #320,d1
  145.                 move.l  #256,d2
  146.                 CALLGRAF        InitBitMap      ;init bitmap structures
  147.                 move.l  #320,d0
  148.                 move.l  #256*8,d1
  149.                 CALLGRAF        AllocRaster     ;allocate bitmap memory
  150.                 tst.l   d0
  151.                 beq.b   .error
  152.                 move.l  d0,a0
  153.                 move.l  #(256*8*320/8/4),d5
  154. .clear
  155.                 clr.l   (a0)+                   ;clear one plane
  156.                 subq.l  #1,d5
  157.                 bne.b   .clear
  158.                 moveq   #8-1,d6
  159. .loop2
  160.                 move.l  d0,(a2)+                ;and insert into bitmap struct
  161.                 add.l   #320/8*256,d0
  162.                 dbra    d6,.loop2
  163.                 moveq   #-1,d0
  164.                 bra.b   .end
  165. .error
  166.                 moveq   #0,d0
  167. .end
  168.                 movem.l (sp)+,d1/d5-a2
  169.                 rts
  170.  
  171. ******************************************************************************
  172. *
  173. *       FreeBitmaps
  174. *
  175. *       frees all the memory allocated by 'AllocRaster'
  176. *
  177. ******************************************************************************
  178. FreeBitmaps
  179.                 movem.l d0/d1/d6-a2,-(sp)
  180.                 lea     bitmap,a0
  181. .loop
  182.                 move.l  a0,a2
  183.                 lea     bm_Planes(a2),a2
  184.                 moveq   #8-1,d6
  185. .loop2
  186.                 move.l  (a2)+,d0                ;read planeptr
  187.                 beq.b   .next
  188.                 move.l  d0,a0
  189.                 move.l  #320,d0
  190.                 move.l  #256,d1
  191.                 CALLGRAF        FreeRaster      ;free the bitmap memory
  192. .next
  193.                 dbra    d6,.loop2
  194.                 movem.l (sp)+,d0/d1/d6-a2
  195.                 rts
  196.  
  197. ******************************************************************************
  198. *
  199. *       ChunkyToPlanar (a0,a1)
  200. *
  201. *       converts chunky data into bitplane data (using Bitmap Structure)
  202. *       works ONLY with a depth of 8 and resolution 320*256.
  203. *       the 8 bitplanes MUST have been allocated in ONE piece!!
  204. *
  205. *       original algorithm by James McCoull (I found the source somewhere
  206. *       on the AMINET CD's)
  207. *
  208. *       In: a0 -> Chunkybuffer
  209. *           a1 -> Bitmap structure
  210. *
  211. ******************************************************************************
  212. ChunkyToPlanar
  213.                 movem.l d0-a6,-(sp)
  214.                 sub.w   #40,sp          ; space for temporary variables
  215.  
  216.                 move.l  #256*40,d2
  217.                 move.l  bm_Planes(a1),a1
  218.  
  219. ; a0 = chunky buffer
  220. ; a1 = output area
  221. ; d2 = plsiz
  222.                 ext.l   d2
  223.                 movea.l d2,a3           ; a3 = plsiz
  224.                 move.l  a0,a4
  225.                 add.l   #320*256,a4     ; a4 -> end of chunky data
  226.  
  227.  
  228. first_case
  229.                 move.l  (0,a0),d1
  230.                 move.l  (4,a0),d3
  231.                 move.l  (8,a0),d0
  232.                 move.l  (12,a0),d2
  233.                 move.l  (2,a0),d4
  234.                 move.l  (10,a0),d5
  235.                 move.l  (6,a0),d6
  236.                 move.l  (14,a0),d7
  237.  
  238.                 move.w  (16,a0),d1
  239.                 move.w  (24,a0),d0
  240.                 move.w  (20,a0),d3
  241.                 move.w  (28,a0),d2
  242.                 move.w  (18,a0),d4
  243.                 move.w  (26,a0),d5
  244.                 move.w  (22,a0),d6
  245.                 move.w  (30,a0),d7
  246.  
  247.                 adda.w  #32,a0
  248.  
  249.                 move.l  d6,a5
  250.                 move.l  d7,a6
  251.  
  252.                 merge   d1,d0,d6,d7,$00ff00ff,8
  253.                 merge   d3,d2,d6,d7,$00ff00ff,8
  254.  
  255.                 merge   d1,d3,d6,d7,$0f0f0f0f,4
  256.                 merge   d0,d2,d6,d7,$0f0f0f0f,4
  257.  
  258.                 exg     d1,a5
  259.                 exg     d0,a6
  260.  
  261.                 merge   d4,d5,d6,d7,$00ff00ff,8
  262.                 merge   d1,d0,d6,d7,$00ff00ff,8
  263.  
  264.                 merge   d4,d1,d6,d7,$0f0f0f0f,4
  265.                 merge   d5,d0,d6,d7,$0f0f0f0f,4
  266.  
  267.                 merge   d3,d1,d6,d7,$33333333,2
  268.                 merge   d2,d0,d6,d7,$33333333,2
  269.  
  270.                 merge   d3,d2,d6,d7,$55555555,1
  271.                 merge   d1,d0,d6,d7,$55555555,1
  272.  
  273.                 move.l  d0,(0*4,sp)             ;plane0
  274.                 move.l  d1,(1*4,sp)             ;plane1
  275.                 move.l  d2,(2*4,sp)             ;plane2
  276.                 move.l  d3,(3*4,sp)             ;plane3
  277.  
  278.                 move.l  a5,d3
  279.                 move.l  a6,d2
  280.  
  281.                 merge   d3,d4,d6,d7,$33333333,2
  282.                 merge   d2,d5,d6,d7,$33333333,2
  283.  
  284.                 merge   d3,d2,d6,d7,$55555555,1
  285.                 merge   d4,d5,d6,d7,$55555555,1
  286.  
  287.                 move.l  d5,(4*4,sp)             ;plane4
  288.                 move.l  d4,(5*4,sp)             ;plane5
  289.  
  290.                 move.l  d2,(6*4,sp)             ;plane6
  291.                 move.l  d3,(7*4,sp)             ;plane7
  292.  
  293.                 move.l  a1,(32,sp)              ; save output address
  294.                 addq.l  #4,a1                   ; skip 32 pixels on output
  295.  
  296.                 cmpa.l  a0,a4
  297.                 beq.w   final_case
  298.  
  299.  
  300.  
  301. main_case
  302.                 move.l  a1,(36,sp)      ; save current output address
  303.                 move.l  (32,sp),a1      ; a1 = previous output address
  304.  
  305.                 move.l  (0,a0),d1
  306.                 move.l  (4,a0),d3
  307.                 move.l  (8,a0),d0
  308.                 move.l  (12,a0),d2
  309.                 move.l  (2,a0),d4
  310.                 move.l  (10,a0),d5
  311.                 move.l  (6,a0),d6
  312.                 move.l  (14,a0),d7
  313.  
  314.                 move.w  (16,a0),d1
  315.                 move.w  (24,a0),d0
  316.                 move.w  (20,a0),d3
  317.                 move.w  (28,a0),d2
  318.                 move.w  (18,a0),d4
  319.                 move.w  (26,a0),d5
  320.                 move.w  (22,a0),d6
  321.                 move.w  (30,a0),d7
  322.  
  323.                 adda.w  #32,a0
  324.  
  325.                 move.l  d6,a5
  326.                 move.l  d7,a6
  327.  
  328.                 move.l  (0*4,sp),(a1)           ;plane0
  329.                 adda.l  a3,a1                   ;a1+=plsiz
  330.  
  331.                 merge   d1,d0,d6,d7,$00ff00ff,8
  332.                 merge   d3,d2,d6,d7,$00ff00ff,8
  333.  
  334.                 move.l  (1*4,sp),(a1)           ;plane1
  335.                 adda.l  a3,a1                   ;a1+=plsiz
  336.  
  337.                 merge   d1,d3,d6,d7,$0f0f0f0f,4
  338.                 merge   d0,d2,d6,d7,$0f0f0f0f,4
  339.  
  340.                 exg     d1,a5
  341.                 exg     d0,a6
  342.  
  343.                 move.l  (2*4,sp),(a1)           ;plane2
  344.                 adda.l  a3,a1                   ;a1+=plsiz
  345.  
  346.                 merge   d4,d5,d6,d7,$00ff00ff,8
  347.                 merge   d1,d0,d6,d7,$00ff00ff,8
  348.  
  349.                 move.l  (3*4,sp),(a1)           ;plane3
  350.                 adda.l  a3,a1                   ;a1+=plsiz
  351.  
  352.                 merge   d4,d1,d6,d7,$0f0f0f0f,4
  353.                 merge   d5,d0,d6,d7,$0f0f0f0f,4
  354.  
  355.                 move.l  (4*4,sp),(a1)           ;plane4
  356.                 adda.l  a3,a1                   ;a1+=plsiz
  357.  
  358.                 merge   d3,d1,d6,d7,$33333333,2
  359.                 merge   d2,d0,d6,d7,$33333333,2
  360.  
  361.                 move.l  (5*4,sp),(a1)           ;plane5
  362.                 adda.l  a3,a1                   ;a1+=plsiz
  363.  
  364.                 merge   d3,d2,d6,d7,$55555555,1
  365.                 merge   d1,d0,d6,d7,$55555555,1
  366.  
  367.                 move.l  d0,(0*4,sp)             ;plane0 (movem.l is slower!)
  368.                 move.l  d1,(1*4,sp)             ;plane1
  369.                 move.l  d2,(2*4,sp)             ;plane2
  370.                 move.l  d3,(3*4,sp)             ;plane3
  371.  
  372.                 move.l  a5,d3
  373.                 move.l  a6,d2
  374.  
  375.                 move.l  (6*4,sp),(a1)           ;plane6
  376.                 adda.l  a3,a1                   ;a1+=plsiz
  377.  
  378.                 merge   d3,d4,d6,d7,$33333333,2
  379.                 merge   d2,d5,d6,d7,$33333333,2
  380.  
  381.                 move.l  (7*4,sp),(a1)           ;plane7
  382.                 adda.l  a3,a1                   ;a1+=plsiz
  383.  
  384.                 merge   d3,d2,d6,d7,$55555555,1
  385.                 merge   d4,d5,d6,d7,$55555555,1
  386.  
  387.                 move.l  d5,(4*4,sp)             ;plane4
  388.                 move.l  d4,(5*4,sp)             ;plane5
  389.  
  390.                 move.l  d2,(6*4,sp)             ;plane6
  391.                 move.l  d3,(7*4,sp)             ;plane7
  392.  
  393.                 movea.l (36,sp),a1      ; restore current output address
  394.                 move.l  a1,(32,sp)      ; save output address
  395.                 addq.l  #4,a1
  396.  
  397.                 cmpa.l  a0,a4
  398.                 bne.w   main_case
  399.  
  400.  
  401. final_case
  402.                 move.l  (32,sp),a1      ; a1 = previous output address
  403.  
  404.                 move.l  (0*4,sp),(a1)           ;plane0
  405.                 adda.l  a3,a1                   ;a1+=plsiz
  406.                 move.l  (1*4,sp),(a1)           ;plane1
  407.                 adda.l  a3,a1                   ;a1+=plsiz
  408.                 move.l  (2*4,sp),(a1)           ;plane2
  409.                 adda.l  a3,a1                   ;a1+=plsiz
  410.                 move.l  (3*4,sp),(a1)           ;plane3
  411.                 adda.l  a3,a1                   ;a1+=plsiz
  412.                 move.l  (4*4,sp),(a1)           ;plane4
  413.                 adda.l  a3,a1                   ;a1+=plsiz
  414.                 move.l  (5*4,sp),(a1)           ;plane5
  415.                 adda.l  a3,a1                   ;a1+=plsiz
  416.                 move.l  (6*4,sp),(a1)           ;plane6
  417.                 adda.l  a3,a1                   ;a1+=plsiz
  418.                 move.l  (7*4,sp),(a1)           ;plane7
  419.  
  420. exit
  421.                 add.w   #40,sp
  422.                 movem.l (sp)+,d0-a6
  423.                 rts
  424.  
  425.  
  426.  
  427.                 section "",data
  428.  
  429. graf_name       GRAFNAME
  430.                 cnop    0,4
  431.  
  432. WRO
  433.                 dc.l    ModName
  434.                 dc.l    Short
  435.                 dc.l    Description
  436.                 dc.l    Author
  437.                 dc.l    VERSION
  438.                 dc.l    REVISION
  439.                 dc.l    REVISIONCOUNT
  440.                 dc.l    0
  441. Result
  442.                 dc.l    0
  443.                 dc.l    RES_MICROSECS
  444.                 dc.l    ResultString
  445.                 dc.l    ResultParams
  446. Status
  447.                 dc.l    0
  448. ErrStr
  449.                 dc.l    0
  450.                 dc.l    ErrParams
  451.                 dc.l    0
  452.  
  453. ModName         dc.b    "C2P",0
  454. Short           dc.b    "ChunkyToPlanar converter (320*256*8)",0
  455. Description     dc.b    "This program measures the time for a ChunkyToPlanar-\n"
  456.                 dc.b    "conversion to complete. The dimensions are 320*256*8.",0
  457. Author          dc.b    "Sam Jordan (original C2P algorithm by James Mc Coull)",0
  458. ResultString    dc.b    "Elapsed time: %ld.%03ld ms",0
  459.  
  460. LibErr          dc.b    "Failed to open %s V%ld",0
  461. MemErr          dc.b    "Failed to allocate %ld bytes or memory",0
  462. ChipErr         dc.b    "Failed to allocate 320*256 bytes of CHIP memory",0
  463.  
  464.                 section "",bss
  465.  
  466. _SysBase        ds.l    1
  467. _GfxBase        ds.l    1
  468. _PowerPCBase    ds.l    1
  469. ActualBitmap    ds.l    1
  470. ChunkyBuffer    ds.l    1
  471. ResultParams    ds.l    2
  472. ErrParams       ds.l    2
  473. bitmap          ds.b    bm_SIZEOF
  474.